<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<?php
if(!isset($_SESSION)){
	session_start();
}

if(!isset($_SESSION["adminName"]) || (empty($_SESSION["adminName"]))){
	header ("Location: ../index.php");
}
?>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Edit Page</title>
    <link href="../../Styles/adminstype.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="../js/admin_script.js"></script>
</head>
<body>
<?php
	$TenLSP = "";
	$getPass = "";
	$getTenHT = "";
	$getDiaChi = "";
	$getDienThoai = "";
	$getEmail = "";
	$getLoaiTK = "";
	$BiXoa = "";
	$checked = "";
	$comboBox = "";
	$id = $_SESSION["edit"];
	
	if(empty($_REQUEST["btnSua"])){
		if($id != "") // kiem tra du lieu
		{
			$sql = "select * from taikhoan where MaTaiKhoan = $id";
				
			require_once "../database/DataProvider.php";
			$result =  DataProvider::ExecuteQuery($sql);
				
			if(!empty($result))
			{
				while ($row=mysql_fetch_array($result)){
					$TenLSP = $row["TenDangNhap"];
					$getPass = $row["MatKhau"];
					$getTenHT = $row["TenHienThi"];
					$getDiaChi = $row["DiaChi"];
					$getDienThoai = $row["DienThoai"];
					$getEmail = $row["Email"];
					$getLoaiTK = $row["MaLoaiTaiKhoan"];
					$BiXoa = $row["BiXoa"];
					$checked = ($row["BiXoa"] == 0 ? '' : 'checked');
				}	
			}
		}
		
		
		// tạo combo loai tai khoảng
		$width = 160;;
		$name ="LoaiTK";
		$active_sltTenTH = $getLoaiTK;
		$tatca = "Tất Cả";
		$comboBox = '<select style="width:'.$width.'px" name="'.$name.'" id="'.$name.'" >'."\n";
		
		$sql = "select * from loaitaikhoan";
		require_once "../database/DataProvider.php";
		$result =  DataProvider::ExecuteQuery($sql);
		
		if(!empty($result)){
			while($row = mysql_fetch_array($result))
			{
				$comboBox .= '<option value="'.$row["MaLoaiTaiKhoan"].'"';
				if($active_sltTenTH == $row["MaLoaiTaiKhoan"]) $comboBox .= ' selected="selected" ';
				$comboBox .= '>'.$row["TenLoaiTaiKhoan"]."</option>\n";
			}
		}
		$comboBox .= "</select>\n";
		
	}
?>
<table>
	<tr class="boxContentTitle">
		<td>Sửa thông tin người dùng</td>
	</tr>
	<tr>
		<td>
			 <form action="resource/form_edit_account.php" method="post" name="form_edit_account">
				<table class="tableBoxView">
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Tên đăng nhập</td>
						<td><input type="text" maxlength="300" name="txtTen" id="txtTen" <?php echo("value='$TenLSP'");?>/></td>
					</tr>
									<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Mật Khẩu</td>
						<td><input type="password" maxlength="64" name="txtPass" id="txtPass" <?php echo("value='$getPass'");?>/></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Tên hiển thị</td>
						<td><input type="text" maxlength="64" name="txtTenHienThi" id="txtTenHienThi" <?php echo("value='$getTenHT'");?>/></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Địa chỉ</td>
						<td><input type="text" maxlength="600" name="txtDiaChi" id="txtDiaChi" <?php echo("value='$getDiaChi'");?>/></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Điện thoại</td>
						<td><input type="text" maxlength="20" name="txtDienThoai" id="txtDienThoai" <?php echo("value='$getDienThoai'");?>/></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Email</td>
						<td><input type="text" maxlength="200" name="txtEmail" id="txtEmail" <?php echo("value='$getEmail'");?>/></td>
					</tr>
					<tr>
						<td style="width: 200px"><td>
						<td style="width: 200px">Loại tài khoảng</td>
						<td><?php echo($comboBox);?></td>
					</tr>
					<tr>
						<td><td>
						<td>Bị xóa</td>
						<td><input type="checkbox" name="Xoa" value="Yes"<?php echo(" ");  echo($checked);?>></td>
					</tr>
					<tr>
						<td><td>
						<td></td>
						<td><input type="submit" name="btnSua" value="Save" onclick="return kiemTraTxt3('txtTen', 'txtPass', 'txtTenHienThi')"/></td>
					</tr>
				</table>
			</form>
		</td>
	</tr>
	<tr>
		<td>
			<?php
			if(!empty($_REQUEST["btnSua"]))//có yeu cau sua
			{
				$tenTK = $_REQUEST["txtTen"];
				$pass = $_REQUEST["txtPass"];
				$tenHT = $_REQUEST["txtTenHienThi"];
				$diaChi = $_REQUEST["txtDiaChi"];
				$dienThoai = $_REQUEST["txtDienThoai"];
				$email = $_REQUEST["txtEmail"];
				$loaiTK = $_REQUEST["LoaiTK"];				
				$xoa = 0;
				if(isset($_REQUEST["Xoa"]) && $_REQUEST["Xoa"] == "Yes"){
					$xoa = 1;
				}

				if($tenTK != "") //  kiểm tra 
				{
					$sql = "UPDATE taikhoan 
    						SET TenDangNhap='" .$tenTK."',
    						MatKhau='" .$pass."',
    						TenHienThi='" .$tenHT."',
    						DiaChi='" .$diaChi."',
    						DienThoai='" .$dienThoai."',
    						Email='" .$email."',
							BiXoa=" .$xoa. ",
							MaLoaiTaiKhoan= $loaiTK WHERE MaTaiKhoan=$id";
					
					echo($sql);
					
					
					require_once "../../database/DataProvider.php";
					$result =  DataProvider::ExecuteQuery($sql);
					echo($result);
				}
				header ("Location: ../admin_manager_account.php");
			}
			?>
		</td>
	</tr>
</table>
</body>
</html>

